home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / PIC_LOAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-02  |  6.0 KB  |  208 lines

  1. /* load up a compressed degas elite pic */
  2. #include <osbind.h>
  3. #define REZ 1                    /* 1 med, 0 low */
  4. #define rnd(t) Random()%(t)   /*returns a number from 0 to (t-1) */
  5.  
  6. char     temp_[32000],                     /* Temp buffer where file is read in    */
  7.          *hld,
  8.          *iff_in, *iff_out;                  /* Pointers for DEGAS unpack() routine    */
  9.  
  10. #include <stdio.h>
  11. int contrl[12];
  12. int intin[256],  ptsin[256];
  13. int intout[256], ptsout[256];
  14.  
  15. char title[] ="Revenge.pc2";
  16. int savepal[16],newpal[16],junkbuff[46],pal2[16];
  17. int filehandle;
  18. main()
  19.  
  20. {
  21.    
  22.     char *scr1,*kill2,*screen;
  23.     int handle,x,kill1;
  24.     
  25.      
  26.    scr1 = malloc(32768+256);  /*allocate memory for 2nd screen */
  27.     if ((long) scr1 & 0xff)
  28.       scr1 = scr1 + (0x100 - (long)scr1 & 0xff);
  29. screen = (char *)Physbase();
  30. read_stuff(title,scr1,1);  /* read main title screen onto the temp scr*/
  31. Setscreen(screen,scr1,-1);
  32. Setpalette(newpal);        /* tel sys to use these colors! */
  33.  
  34.  
  35.  do
  36.      {
  37.     ; /* nothing */
  38.      } while ( !Bconstat(2));      /* while no input */
  39.      
  40.  
  41. /*
  42. x=0;
  43.  do                  destroy pic! cool!! 
  44.   {
  45.    kill1 = rnd(32760);
  46.    kill2 = kill1+scr1;
  47.    *kill2=0; 
  48.   } while (x++ < 32766);*/
  49. Setscreen(screen,screen,-1);  
  50. Setpalette(savepal);      /* restore palette */
  51.  
  52. }
  53.  
  54. /* load degas compressed pics */
  55.  
  56. /************************/
  57. read_stuff(hold,adrr,which)
  58. char hold[];
  59. register char *adrr;
  60. int which;  
  61. /* if which = 1 then store palette into newpal*/
  62. /* which is the main pal of the game. If = 0 then store */
  63. /* into pal2. the alternate pal of the game */
  64.  
  65. {
  66.  char buf[130];
  67.  int lines,i;
  68.  
  69.  /*v_gtext(handle,1,5,"in read stuff");*/
  70.  
  71. filehandle = Fopen(hold,0); 
  72.  
  73. for(i=0; i<16;i++)
  74.  savepal[i]=Setcolor(i,-1);
  75. /* read header data */
  76. i=Fread(filehandle,2L,buf);
  77.  
  78.  
  79. /* read 16 words of palette data into newpal array */
  80. if(which==0) i = Fread(filehandle,32L,pal2); /* save pal2 */
  81. else
  82. i =Fread(filehandle,32L,newpal);
  83.  
  84.  
  85.  
  86.  
  87. i=Fread(filehandle,32000L,temp_);  /* read image onto back screen*/
  88. /* Close file */
  89. Fclose(filehandle);
  90.      lines = 200;                     /* Low, med-res    */
  91.                  iff_in  = temp_;                /* iff_in pts to temp_buf*/
  92.                  iff_out = adrr;      /* iff_out pts to pic_buffer*/
  93.                   do        
  94.          unpack(REZ);                                      /* Unpack a line at a time */
  95.                   while (--lines); 
  96.  
  97.  
  98.  /*v_gtext(handle,1,5,"             ");*/
  99.        
  100. }
  101. /************************/
  102.  
  103. /***********************/
  104.  
  105. /*---------------------------------------------------------------------------*/
  106. /*                             |--------- DEGAS ---------|            */
  107. /*                              UNCOMPRESSED   COMPRESSED            */
  108. /*                 NEO  low med mono   low med mono     TINY    */
  109. /*    typ...        0     1   2   3     4   5   6     7        */
  110.  
  111. /* Unpacks a single scan line & updates iff_in & iff_out global pointers
  112.  
  113.                      /    byt ==  0 to  127  copy next [byt+1] bytes
  114. Unpack routine --if-<    byt == -1 to -127  copy next byte [-byt+1] times
  115.                      \    byt == 128         NO-OP                            */
  116.  
  117. unpack(rez)
  118. int     rez;
  119.  
  120. {
  121.     register char     *src_ptr, *dst_ptr,           /* ptrs to source/dest */
  122.               byt, cnt;                     /* byt holds the ACTUAL compressed data code(control byte ) */
  123.     register int      minus128 = -128, 
  124.               len;                          
  125.     char                 linbuf[320];                            /* Oversize just in case! */
  126.     int                      llen;
  127.  
  128.  
  129.     if (rez < 2)     len = 160;
  130.     else             len = 80;
  131.     llen = len;
  132.     src_ptr = iff_in;           /* iff_in is ptr to compressed data */
  133.     dst_ptr = &linbuf[0];       /* linbuf WILL hold an ENTIRE Uncompressed scan line. 4 bitplanes * 80 = 320 max! */ 
  134.  
  135.     while (len > 0)
  136.    {
  137.             byt = *src_ptr++;       /* get byte value at address scr_ptr, THEN inc scr_ptr+1 */
  138.             if (byt >= 0)           /* If ctrl code >= 0 then use the next x+1 bytes*/
  139.     {
  140.                  ++byt;                 /* inc byt +1 */
  141.                   do 
  142.        {
  143.                         *dst_ptr++ = *src_ptr++;  /* get byte value from address source, and inc the 2 ptrs */
  144.                         --len;                    /* one byte down.. */
  145.                    }
  146.          while (--byt);           /* do this byt TIMES (remember byt here = byt+1 */
  147.              }
  148.              else 
  149.        if (byt != minus128)       /* else if ctrl code NOT = -128*/
  150.          {                        /*Then use the next byte -x+1 times, (-x) cause x will be negative and - - = + */
  151.                       cnt = -byt + 1;         /* cnt = -x + 1 */
  152.                       byt = *src_ptr++;       /* byt = THE very next byte past the ctrl code(or ctrl byte! */
  153.                        do {
  154.                                *dst_ptr++ = byt;  /* store that byte */
  155.                                --len;         
  156.                           }
  157.                while (--cnt);    /* keep doing it cnt times */
  158.                   }
  159.         }
  160.  
  161.     ilbm_st(linbuf, iff_out, rez);   /* convert the format line */
  162.     iff_in = src_ptr;                                    /* Update global pointers */
  163.     iff_out += llen;
  164.  
  165. }                                /* end of module uncompress() */
  166.  
  167. /*---------------------------------------------------------------------------*/
  168.  
  169. ilbm_st(src_ptr, dst_ptr, rez)           /* Convert ILBM format line to ST format */
  170. int         *src_ptr, *dst_ptr, rez;
  171. {
  172.     int         x, *p0_ptr, *p1_ptr, *p2_ptr, *p3_ptr;
  173.  
  174.     if (rez==0) 
  175.  {                                                     /* Low-res */
  176.   
  177.         p0_ptr = src_ptr;
  178.         p1_ptr = src_ptr + 20;
  179.         p2_ptr = src_ptr + 40;
  180.         p3_ptr = src_ptr + 60;
  181.         for (x=0; x<20; ++x)
  182.   {
  183.                *dst_ptr++ = *p0_ptr++;
  184.                *dst_ptr++ = *p1_ptr++;
  185.                *dst_ptr++ = *p2_ptr++;
  186.                *dst_ptr++ = *p3_ptr++;
  187.           }
  188.     } 
  189.  else if (rez==1) 
  190.   {                                            /* Med-res */
  191.            p0_ptr = src_ptr;
  192.            p1_ptr = src_ptr + 40;
  193.            for (x=0; x<40; ++x)
  194.     {
  195.                  *dst_ptr++ = *p0_ptr++;
  196.                  *dst_ptr++ = *p1_ptr++;
  197.             }
  198.     }
  199.     else 
  200.      {                                                   /* Monochrome */
  201.               for (x=0; x<40; ++x)
  202.                   *dst_ptr++ = *src_ptr++;
  203.          }
  204.  
  205.  }
  206. /*---------------------------------------------------------------------------*/
  207.  
  208.